﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows;

namespace AJWPFAdmin.Core.ExtensionMethods
{
    public static class DependencyObjectExt
    {
        public static T GetFirstVisualChild<T>(this DependencyObject depObj) where T : DependencyObject
        {
            if (depObj == null) return null;
            for (var i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
            {
                var child = VisualTreeHelper.GetChild(depObj, i);
                if (child is T tChild)
                {
                    return tChild;
                }
                var childItem = GetFirstVisualChild<T>(child);
                if (childItem != null) return childItem;
            }
            return null;
        }
    }
}
